package com.dd.ljzapplication.fragment.lazy;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;

import com.bumptech.glide.Glide;
import com.dd.ljzapplication.R;
import com.emiage.ddutils.LogUtils;
import com.emiage.ddutils.UIUtils;

import java.util.ArrayList;

/**
 * Created by LiJZ on 2016/11/29.
 */

public class LFragmentFour extends LazyFragment{

	private ListView mListView;
	private ArrayList<String> mListData;
	@Override
	public int getLayoutId() {
		return R.layout.lfragment_four;
	}

	@Override
	public void initview() {
		mListView = (ListView) mFragmentView.findViewById(R.id.lv);
		mListData = new ArrayList<>();
		String url1 = "http://pic28.nipic.com/20130424/11588775_115415688157_2.jpg";
		String url2 = "http://bizhi.zhuoku.com/2011/01/09/jingxuan/Jingxuan263.jpg";
		String url3 = "http://pic56.nipic.com/file/20141227/19674963_215052431000_2.jpg";
		String url4 = "http://i1.hexunimg.cn/2014-08-15/167580248.jpg";
		String url5 = "http://pic1a.nipic.com/2009-02-26/2009226135011839_2.jpg";
		String url6 = "http://h.hiphotos.baidu.com/image/pic/item/eaf81a4c510fd9f9a8ccabb6212dd42a2934a412.jpg";
		String url7 = "http://h.hiphotos.baidu.com/image/h%3D200/sign=e72c850a09f3d7ca13f63876c21fbe3c/a2cc7cd98d1001e9460fd63bbd0e7bec54e797d7.jpg";
		String url8 = "http://h.hiphotos.baidu.com/image/h%3D200/sign=33cd08a6d01b0ef473e89f5eedc551a1/f9198618367adab4dde25bcb89d4b31c8701e40c.jpg";
		String url9 = "http://c.hiphotos.baidu.com/image/h%3D200/sign=ad9932e8d300baa1a52c40bb7711b9b1/b219ebc4b74543a9b08205c81c178a82b901141c.jpg";
		String url10 = "http://h.hiphotos.baidu.com/image/h%3D200/sign=32a2719184cb39dbdec06056e01709a7/8ad4b31c8701a18b68b007349b2f07082838fe76.jpg";

		mListData.add(url1);
		mListData.add(url2);
		mListData.add(url3);
		mListData.add(url4);
		mListData.add(url5);
		mListData.add(url6);
		mListData.add(url7);
		mListData.add(url8);
		mListData.add(url9);
		mListData.add(url10);

		MyAdapter adapter = new MyAdapter();
		mListView.setAdapter(adapter);
	}

	@Override
	public void initLazyLodeData() {
		for (int i = 0; i < 3; i++) {
			LogUtils.d("第四个Fragment的懒加载数据：" + i);
		}
	}

	@Override
	public void initData() {
//		for (int i = 0; i < 3; i++) {
//			LogUtils.e("第四个Fragment的数据：" + i);
//		}
	}

	@Override
	public void initEvent() {

	}

	@Override
	public void InVisibleEvent() {

	}

	private class MyAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			return mListData.size();
		}

		@Override
		public Object getItem(int position) {
			return mListData.get(position);
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, android.view.View convertView, ViewGroup parent) {
			ViewHolder holder;
			if (convertView == null) {
				convertView = UIUtils.inflate(R.layout.item_glide);
				holder = new ViewHolder();
				holder.mImageView = (ImageView) convertView.findViewById(R.id.iv_glide);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}

			Glide.with(LFragmentFour.this).load(mListData.get(position)).into(holder.mImageView);

			return convertView;
		}
	}

	private class ViewHolder {
		ImageView mImageView;
	}
}
